<template>
  <div class="containerFluid px-0 flex-shrink-0">
    <GlobalHeader :user="user"></GlobalHeader>
    <Loader v-if="isLoading"></Loader>
    <router-view></router-view>
    <Footer></Footer>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed, watch } from 'vue'
import GlobalHeader from './components/GlobalHeader.vue'
import Loader from './components/Loader.vue'
import Footer from './components/Footer.vue'
import 'bootstrap/dist/css/bootstrap.min.css'
import CreateMessage from './components/CreateMessage'
import { useStore } from 'vuex'
import { GlobalDataProps } from './store'
export default defineComponent({
  name: 'App',
  components: {
    GlobalHeader,
    Loader,
    Footer
  },
  setup() {
    const store = useStore<GlobalDataProps>()
    const currentUser = computed(() => store.state.user)
    const isLoading = computed(() => store.state.loading)
    const error = computed(() => store.state.error)
    watch(
      () => error.value.status,
      () => {
        const { status, message } = error.value
        if (status && message) {
          CreateMessage(message, 'error')
        }
      }
    )
    return {
      user: currentUser,
      isLoading,
      error
    }
  }
})
</script>
